<template>
  <div v-if="isShow">
    <div class="wrap">
      <div class="dialog" :style="{width}">
        <div class="dialog-header" v-if="isHeaderShow">
          <slot name="header">
            {{ title }}
            <i class="el-icon-close" @click="close"></i>
          </slot>
        </div>
        <div class="dialog-body">
          <slot>中间</slot>
        </div>
        <div class="dialog-fotter" v-if="isFooterShow">
          <slot name="fotter">
            底部
          </slot>
        </div>
      </div>
    </div>
    <div class="modal"></div>
  </div>
</template>

<script>
export default {
  name: 'Dialog',
  data() {
    return {
      isShow: false
    }
  },
  props: {
    title: {
      type: String,
      default: ''
    },
    width: {
      type: String,
      default: '450px'
    },
    isHeaderShow: {
      type: Boolean,
      default: true
    },
    isFooterShow: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    close() {
      this.isShow = false
      this.$emit('dialogClose')
    },
    open() {
      this.isShow = true
    }
  }
}
</script>

<style lang="scss" scoped>
.wrap{
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  margin: 0;
  z-index: 999;
  .dialog{
    margin: 15vh auto;
    width: 450px;
    background-color: #fff;
    box-shadow: 0px 2px 14px 0px rgba(153, 153, 153, 0.5);
    border-radius: 8px;
    font-size: 16px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.85);
    .dialog-header{
      height: 55px;
      padding: 0 29px;
      line-height: 55px;
      box-sizing: border-box;
      border-bottom: 1px solid #E9E9E9;
      .el-icon-close{
        float: right;
        margin-top: 19px;
        cursor: pointer;
      }
    }
  }
}
.modal{
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  opacity: .5;
  background: #000;
  z-index: 998
}
</style>
